<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" width="560px" top="0" append-to-body>
		<el-form v-bind="formConfig" :model="formData" :rules="formRules" label-width="80px" v-loading="loading">
			<el-row :gutter="16">
				<el-col :span="24">
					<el-form-item label="角色名称" prop="name">
						<el-input v-model="formData.name"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="11">
					<el-form-item label="角色类型" prop="userType">
						<el-select v-model="formData.userType" placeholder="请选择角色类型">
							<el-option v-for="(item, index) in list" :key="index" :label="item.deName" :value="item.deValue"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="13">
					<el-form-item label="权限等级" prop="dataScope">
						<el-select v-model="formData.dataScope" placeholder="请选择数据权限等级">
							<el-option label="低权 - 仅自己" value="1"></el-option>
							<el-option label="中低权 - 本部门" value="3"></el-option>
							<el-option label="中权 - 本部门及以下" value="5"></el-option>
							<el-option label="中高权 - 自定义" value="7"></el-option>
							<el-option label="高权 - 所有" value="9"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="formData.dataScope === '7'">
					<el-form-item label="权限部门">
						<sw-tree-multi-select v-model="formData.depts" :tree-data="departTree" :defaultProps="defaultProps" placeholder="请选择权限部门" />
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="角色描述">
						<el-input type="textarea" v-model="formData.content"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button size="medium" @click="visible = false">取消</el-button>
			<el-button size="medium" type="primary" @click="handleSubmitForm()">确定</el-button>
		</template>
	</el-dialog>
</template>

<script>
import { mapGetters } from 'vuex';
import formMixins from '@/mixins/formMixins';
import { queryRole, addedRole, updateRole } from '@/api/system/tbSysRole';
export default {
	mixins: [formMixins],
	props: {
		list: { type: Array, default: () => [] }
	},
	data() {
		return {
			formName: '角色',
			formRules: {
				name: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
				userType: [{ required: true, message: '请选择角色类型', trigger: 'change' }],
				dataScope: [{ required: true, message: '请选择数据权限等级', trigger: 'change' }]
			},
			defaultProps: { label: 'name', children: 'childList' }
		};
	},
	computed: {
		...mapGetters(['departTree']),
		detailData() {
			return eval(queryRole);
		},
		callFunction() {
			return eval(this.addOrEdit ? addedRole : updateRole);
		}
	},
	methods: {}
};
</script>
